package md.lanjing.com.module_home.contact;

import android.content.Context;

import com.lxh.baselibray.constant.Constant;
import com.lxh.baselibray.mvp.BasePresent;
import com.lxh.baselibray.mvp.IBaseView;
import com.lxh.baselibray.net.NetCallBack;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.SPUtils;
import com.lxh.baselibray.util.ToastUtils;

import md.lanjing.com.module_home.R;
import md.lanjing.com.module_home.api.HomeApiService;
import md.lanjing.com.module_home.bean.NearDayProfitResponce;
import md.lanjing.com.module_home.bean.TodayProfitResponce;
import retrofit2.Call;
import retrofit2.Response;

public class TodayProfitContact {
    public static class TodayProfitPresent extends BasePresent<ITodayProfitView> {
        public void getTodayProfit(final Context context){
            HomeApiService service= ServiceGenerator.createService(HomeApiService.class);
            int userId= SPUtils.getInt(Constant.USER_ID,-1,context);
            service.getTodayProfit(userId).enqueue(new NetCallBack<TodayProfitResponce>() {
                @Override
                public void onSuccess(Call<TodayProfitResponce> call, Response<TodayProfitResponce> response) {
                    if (getView()!=null){
                        getView().getTodayProfitData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,context.getString(R.string.request_failed));
                }
            });
        }
        public void getNearProfit(final Context context){
            HomeApiService service= ServiceGenerator.createService(HomeApiService.class);
            int userId= SPUtils.getInt(Constant.USER_ID,-1,context);
            service.getNearProfit(userId).enqueue(new NetCallBack<NearDayProfitResponce>() {
                @Override
                public void onSuccess(Call<NearDayProfitResponce> call, Response<NearDayProfitResponce> response) {
                    if (getView()!=null){
                        getView().getNearProfitData(response);
                    }
                }

                @Override
                public void onFailed() {
                    ToastUtils.showLongToast(context,context.getString(R.string.request_failed));
                }
            });
        }
    }
    public interface ITodayProfitView extends IBaseView {
        void getTodayProfitData(Response<TodayProfitResponce> response);
        void getNearProfitData(Response<NearDayProfitResponce> response);
    }
}
